import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

export default new Vuex.Store({
	actions:{
		gotoNextSong(context,value){
			context.commit('GOTO_NEXTSONG',value)
		}
	},
	mutations:{
		GOTO_NEXTSONG(state,value){
		 const playListId = state.playList.map(v => v.id)
		 for(let i = 0; i < playListId.length; i++){
			 if(value === playListId[i]){
				 state.nextId = playListId[i+1]
			 }
		 }
		},
		GET_PLAYLIST(state,value){
			state.playList = value
		}
	},
	state:{
		playList:[],
		nextId:''
	}
})

